<template>
	<view>
		<view class="container u-skeleton">
			<u-form :errorType="errorType" :model="form" ref="uForm" :label-width="200">
				<view class="line"></view>			
					<u-alert-tips type="warning" class="u-m-20" v-if="statusTitle != ''" :title="statusTitle"></u-alert-tips>
				<view class="content">
					<view class="avatar">
						<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="" prop="imgUrl" :border-bottom="false">
							<view class="f-logo u-skeleton-circle" :style="{ backgroundImage: 'url(' + avatar + ')' }"><image :src="logoMask" mode="aspectFill"></image></view>
						</u-form-item>
							<view class="slot-btn" v-show="!disabled" @tap="chooseAvatar">
								<view class="name u-skeleton-fillet">
									点击更换头像
								</view>
							</view>
						<!-- </u-upload> -->
					</view>
					<view class="header">
						<image class="header-icon u-skeleton-rect" src="../../static/mine/homepage/grxx.png" />
						<view class="header-title u-skeleton-rect">个人信息</view>
					</view>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="编号" prop="industry">
						<view style="width:100%;text-align: right;">{{userCode}}</view>
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="产业" :required="required" prop="industry">
						<view style="width:100%;text-align: right;" v-if="statusTitle != '审核中'" @click="cySelect">{{form.industry || "请选择"}}</view>
						<view style="width:100%;text-align: right;" v-else>{{form.industry || "请选择"}}</view>
						<TriTree ref="cyTree" :multiple="false" :range="fetchDict.industry" @confirm="function (e){return setChooseType(e,'industry')}"></TriTree>
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="姓名" :required="required" prop="cardName">
						<u-input  :disabled="disabled"  placeholder="请真实输入姓名" v-model="form.cardName" input-align="right" />
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :label-width="345" :required="required" label="性别" prop="sexValue">
						<view style=" width:100%;text-align: right;" v-if="statusTitle != '审核中'">
						<u-radio-group style="display: flex;" v-model="form.sex" @change="checkboxGroupChange" width="auto">
							<u-radio shape="square" v-model="item.checked" v-for="(item, index) in sexList" :key="index" :name="item.name">{{ item.name }}</u-radio>
						</u-radio-group>
						</view>
						<view v-else style="width:100%;text-align: right;">{{form.sex}}</view>
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="毕业院校" :required="required" prop="school">
						<u-input  :disabled="disabled"  v-model="form.school" placeholder="请输入毕业院校" input-align="right" />
					</u-form-item>
					<view class="sctp u-m-l-30 u-m-t-40">
						<text class="hz u-skeleton-rect">上传毕业证书<text class="sm u-skeleton-rect">(选填)</text></text>
						<text class="sm u-skeleton-rect">无证书请上传身份证作为实名审核依据</text>
					</view>
					<u-form-item :label-position="labelPosition" prop="photo" label-width="150">
						<block v-if="statusTitle != '审核中'">
						<u-upload ref="uUpload" @on-uploaded="onUploadedZl" :custom-btn="customBtn" :show-upload-list="showUploadList"
						 :action="action" :auto-upload="autoUpload" :file-list="diplomas" @on-remove="onRemove" :show-progress="showProgress"
						 :deletable="deletable" max-count="1" :site="baseUrl">
							<view v-if="customBtn" slot="addBtn" class="slot-btn u-skeleton-rect" hover-class="slot-btn__hover" hover-stay-time="150">
								<u-icon name="photo" size="60" :color="$u.color['lightColor']"></u-icon>
							</view>
						</u-upload>
						</block>
						<block v-else>
							<u-upload v-if="diplomas.length > 0" ref="uUpload"  @on-uploaded="onUploadedZl" :custom-btn="customBtn" :show-upload-list="showUploadList"
							 :action="action" :auto-upload="autoUpload" :file-list="diplomas" @on-remove="onRemove" :show-progress="showProgress"
							 :deletable="disdeletable" max-count="1" :site="baseUrl">
								<view v-if="customBtn" slot="addBtn" class="slot-btn u-skeleton-rect" hover-class="slot-btn__hover" hover-stay-time="150">
									<u-icon name="photo" size="60" :color="$u.color['lightColor']"></u-icon>
								</view>
							</u-upload>
						</block>
					</u-form-item>
					<view class="sctp u-m-l-30 u-m-t-40">
						<view class="hz u-skeleton-rect">上传身份证<text class="sm u-skeleton-rect">(选填)</text></view>
						<text class="sm u-skeleton-rect">请上传身份证头像面和国徽面</text>
					</view>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :label-position="labelPosition" prop="photo" label-width="150">
						<block v-if="statusTitle != '审核中'">
						<u-upload ref="uUpload" @on-uploaded="onUploadedCard" :custom-btn="customBtn" :show-upload-list="showUploadList"
						 :action="action" :auto-upload="autoUpload" :file-list="cardIds" @on-remove="onRemove" :show-progress="showProgress"
						 :deletable="deletable" max-count="2" :site="baseUrl">
							<view v-if="customBtn" slot="addBtn" class="slot-btn u-skeleton-rect" hover-class="slot-btn__hover" hover-stay-time="150">
								<u-icon name="photo" size="60" :color="$u.color['lightColor']"></u-icon>
							</view>
						</u-upload>
						</block>
						<block v-else>
							<u-upload v-if="showUploadList.length > 0" ref="uUpload"  @on-uploaded="onUploadedCard" :custom-btn="customBtn" :show-upload-list="showUploadList"
							 :action="action" :auto-upload="autoUpload" :file-list="cardIds" @on-remove="onRemove" :show-progress="showProgress"
							 :deletable="disdeletable" :max-count="cardIds.length" :site="baseUrl">
								<view v-if="customBtn" slot="addBtn" class="slot-btn u-skeleton-rect" hover-class="slot-btn__hover" hover-stay-time="150">
									<u-icon name="photo" size="60" :color="$u.color['lightColor']"></u-icon>
								</view>
							</u-upload>
						</block>
					</u-form-item>
					
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="个人身份" :required="required" prop="userIdentify">
						<view style="width:100%;text-align: right;"  v-if="statusTitle != ''">{{form.userIdentify || "请选择"}}</view>
						<view v-else style="width:100%;text-align: right;" @click="qySelect">{{form.userIdentify || "请选择"}}</view>
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :required="required"   v-if="specialtyList != undefined" label="具体身份" prop="specialty">
						<view style="width:100%;text-align: right;"  v-if="statusTitle != ''">{{form.specialty || "请选择"}}</view>
						<view style="width:100%;text-align: right;" v-else @click="showLB">{{form.specialty || "请选择"}}</view>
						<u-picker
							mode="selector"
							v-model="specialtyShow"
							@confirm="function (e){return confirm(e,specialtyList,'specialty')}"
							:range="specialtyList"
							:range-key="rangKey"
						></u-picker>
					</u-form-item>
					<!-- 	
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="专业" prop="major">
						<u-input  :disabled="disabled"  placeholder="请输入专业" v-model="form.major" input-align="right" />
					</u-form-item> -->
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect"  label="职称" prop="profession">
						<block v-if="statusTitle != ''">
							<view class="value" style="width:100%;text-align: right;">{{form.profession || "请选择职称"}}</view>
						</block>
						<block v-else>
						<view  v-if=" specialtyList != undefined && specialtyList[specialtyKey] != undefined"  class="value" style="width:100%;text-align: right;" @click="showProfession">{{form.profession || "请选择职称"}}</view>
						<u-input v-else disabled="disabled" placeholder="无" v-model="form.profession" input-align="right" />
						</block>
						<u-picker
							v-if=" specialtyList != undefined && specialtyList[specialtyKey] != undefined"
							mode="selector"
							v-model="professionShow"
							@confirm="function(e){return confirm(e,specialtyList[specialtyKey].jobTitle,'profession')}"
							:range="specialtyList[specialtyKey].jobTitle"
						></u-picker>
						<u-upload v-if="statusTitle != '审核中'" max-count="9"  @on-remove="onRemove" :custom-btn="true" :action="action" :show-upload-list="false" @on-success="avaUploadSuccess2">
							<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
								<image src="../../static/mine/homepage/upload.png" style="width: 48upx;height: 48upx;margin-left: 20upx;" />
							</view>
						</u-upload>
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect line-break"  v-if="proUrls != undefined && proUrls.length > 0" label="职称证书" prop="proUrl">
						<view  style="position: relative;" v-for="(item,index) in proUrls" :key="index">
							<image style="width: 214upx;height: 214upx;margin-right:30rpx;" :src="baseUrl+item" @tap="previewImage(item,proUrls)" ></image>
							<u-icon name="close-circle-fill" style="position: absolute;top: -16upx;right: 15rpx;font-size: 36upx;color: #f00;"  v-if="statusTitle != '审核中'"
							 @click="handleClearProUrl(index)"></u-icon>
						</view>
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect"  label="执业资格" prop="credentials">
						<block v-if="statusTitle != ''">
							<view class="value" style="width:100%;text-align: right;">{{form.credentials || "请选择执业资格"}}</view>
						</block>
						<block v-else>
						<view v-if="specialtyList != undefined && specialtyList[specialtyKey] != undefined" class="value" style="width:100%;text-align: right;"  @click="showCredentials">{{form.credentials || "请选择执业资格"}}</view>
						<u-input v-else disabled="disabled" placeholder="无" v-model="form.credentials" input-align="right" />
						</block>
						<u-picker
							v-if="specialtyList != undefined && specialtyList[specialtyKey] != undefined"
							mode="selector"
							v-model="credentialsShow"
							@confirm="function(e){return confirm(e,specialtyList[specialtyKey].qualificationCert,'credentials')}"
							:range="specialtyList[specialtyKey].qualificationCert"
						></u-picker>
						<u-upload v-if="statusTitle != '审核中'" max-count="9" :custom-btn="true" :action="action" :show-upload-list="false" @on-success="avaUploadSuccess3">
							<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
								<image src="../../static/mine/homepage/upload.png" style="width: 48upx;height: 48upx;margin-left: 20upx;" />
							</view>
						</u-upload>
					</u-form-item>				
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect line-break" v-if="credentialsUrls != undefined && credentialsUrls.length > 0"   label="执业资格证书" prop="credentialsUrl"
					 :border-bottom="false">
						<view  style="position: relative;" v-for="(item,index) in credentialsUrls" :key="index">
							<image style="width: 214upx;height: 214upx;margin-right:30rpx;" :src="baseUrl+item"  @tap="previewImage(item,credentialsUrls)"></image>
							<u-icon name="close-circle-fill" style="position: absolute;top: -16upx;right: 15rpx;font-size: 36upx;color: #f00;" v-if="statusTitle != '审核中'"
							 @click="handleClearProUrl2"></u-icon>
						</view>
					</u-form-item>				
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :required="required"   :label-width="200" label="擅长领域" prop="specials">
						<view v-if="statusTitle != '审核中'" style="width:100%;text-align: right;" @click="mSelect">{{form.specials || "请选择"}}</view>
						<view v-else style="width:100%;text-align: right;">{{form.specials || "请选择"}}</view>	
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :required="required"  label-width="200" v-if="cy == '1135'" label="专业方向" prop="professional">
						<view v-if="statusTitle != '审核中'" style="width:100%;text-align: right;" @click="zySelect">{{form.professional || "请选择"}}</view>
						<view v-else style="width:100%;text-align: right;">{{form.professional || "请选择"}}</view>
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="工作年限" prop="workingSeniority">
						<view style="width:100%;text-align: right;" v-if="statusTitle != '审核中'" @click="showWorkingSeniority = true">{{form.workingSeniority || "请选择"}}</view>
						<view style="width:100%;text-align: right;" v-else>{{form.workingSeniority || "请选择"}}</view>
						<u-picker
							mode="selector"
							v-model="showWorkingSeniority"
							@confirm="function (e){return nxconfirm(e,workingSenioritys,'workingSeniority')}"
							:range="workingSenioritys"
							range-key="label"
						></u-picker>
					</u-form-item>
				</view>
				<view class="line"></view>
				<view class="content" style="padding-top: 0;">
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :label-width="200" label="档期" prop="schedule" style="padding-bottom:10rpx;" :border-bottom="false">
						<view style="width:100%;text-align: right;" v-if="statusTitle != '审核中'" @click="show = true">{{form.schedule || "请选择"}}</view>
						<view style="width:100%;text-align: right;" v-else>{{form.schedule || "请选择"}}</view>
						<u-calendar v-model="show" ref="calendar" @change="change" :mode="mode"
							:start-text="startText" :end-text="endText" :range-color="rangeColor" max-date="2022-10-01"
							:range-bg-color="rangeBgColor" :active-bg-color="activeBgColor"
						>
						</u-calendar>
					</u-form-item>
					<view class="u-p-l-30 u-p-r-30 u-p-b-30 u-border-bottom u-flex u-row-right">
						<text style="color: #9da2b0;">表示此段时间忙碌不接受新合作</text>
					</view>	
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="工作单位" prop="workUnit">
						<u-input  :disabled="disabled"  placeholder="请输入工作单位" v-model="form.workUnit" input-align="right" />
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="工作地点" prop="workplace">
						<view  v-if="statusTitle != '审核中'" style="width:100%;text-align: right;" @click="cityActive = true">{{form.workplace || "请选择"}}</view>
						<view  v-else  style="width:100%;text-align: right;">{{form.workplace || "请选择"}}</view>
						
					<!-- 	<u-input  v-if="statusTitle != '审核中'"  type="select" :select-open="showCity" v-model="form.workplace" placeholder="请选择工作地点" placeholderStyle="color:#0D1D36" input-align="right" @click="showCity = true"></u-input>
						<u-input  :disabled="disabled" v-else  type="select" :select-open="showCity" v-model="form.workplace" placeholder="请选择工作地点" placeholderStyle="color:#0D1D36" input-align="right"></u-input>
						<u-select :default-value="defaultValue" v-model="showCity" mode="mutil-column-auto" value-name="value" label-name="name" child-name="submenu" :list="listCitys" @confirm="confirmCity"></u-select>			 -->
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :required="required" label="联系电话" prop="telephone">
						<u-input  :disabled="disabled"  placeholder="请输入联系电话" v-model="form.telephone" input-align="right" />
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :required="required" label="邮箱" prop="mail">
						<u-input  :disabled="disabled"  placeholder="请输入邮箱" v-model="form.mail" input-align="right" />
					</u-form-item>
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :required="required" label="自定义展示" prop="customize">
						<view style="flex: 1;text-align: right;" @click="handleClickCustom(form.customize)"><text style="color: #9da2b0;">请慎重，如无设置系统默认全部</text>
							<u-icon name="arrow-right" style="color:#9DA2B0;font-size: 32upx;"></u-icon>
						</view>

					</u-form-item>
					<!-- <u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" :label-width="200" label="匹配权重" prop="weight">
						<view style="flex: 1;text-align: right;" @click="handleClickWeight()">
							<u-icon name="arrow-right" style="color:#9DA2B0;font-size: 32upx;"></u-icon>
						</view>				
					</u-form-item> -->
					<u-form-item class="u-m-t-5 u-m-b-5 u-skeleton-rect" label="自评标签" :label-width="150" :border-bottom="false" prop="selfTag">
						<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="0">
							<u-tag v-for="(item,index) in tagList" style="padding: 12upx 16upx;margin-right: 15upx;" :text="item" mode="plain"
							 :key="index" shape="circle" closeable @close="tagClick(index)" />
						</scroll-view>
						<u-button type="primary" style="height: 50upx;border-radius: 22upx;width: 120upx;margin: 0;margin-left: auto;" v-if="statusTitle != '审核中'"
						 @click="popupActive = true">
							<u-icon name="plus"></u-icon>添加
						</u-button>
					</u-form-item>
				</view>
				<view class="line"></view>
				<view class="content">
					<view class="header u-m-t-0">
						<image class="header-icon" src="../../static/mine/homepage/jj.png" />
						<view class="header-title">简介</view>
					</view>
					<u-form-item class="u-p-l-0 u-p-r-10 u-m-t-5 u-m-b-5 u-skeleton-rect" label="" :border-bottom="false" prop="texts">
						<u-input  :disabled="disabled"  v-model="form.texts" type="textarea" style="background: #F5F5F9;padding: 30upx 25upx;" :autoHeight="true"
						 :height="150" :maxlength="300" placeholder="请输入简介" />
					</u-form-item>
				</view>
				<view class="line"></view>
				<view class="content">
					<view class="header u-m-t-0">
						<image class="header-icon" src="../../static/mine/homepage/cpxx.png" />
						<view class="header-title">产品信息介绍</view>
						<u-button type="primary" style="height: 50upx;border-radius: 22upx;width: 120upx;margin: 0;margin-left: auto;margin-right: 40upx;"  v-if="statusTitle != '审核中'"
						 @click="handleClickAddInfo">
							<u-icon name="plus"></u-icon>添加
						</u-button>
					</view>
					<view class="cpInfoList">
						<view class="infoItem" v-if="infoList.length > 0" v-for="(item,index) in infoList" :key="index">
							<view class="item-cell">
								<view class="infoItem-title">分类名称</view>
								<input v-model="item.name" placeholder="请输入分类名称" />
							</view>
							<view class="item-cell">
								<view class="infoItem-title">说明</view>
								<input v-model="item.content" placeholder="请输入产品说明" />
							</view>
							<view class="item-cell">
								<view class="u-flex" @click="getImageTypeIndex(index)">
									<block v-if="item.arr != undefined">
									<image v-for="(imgItem,imgIndex) in item.arr" :key="imgIndex" :src="imgItem" style="width: 196upx;height: 196upx;margin:10upx;"></image>
									</block>
									<u-upload :custom-btn="true" :action="action" @on-success="avaUploadSuccess4" :show-progress="showProgress"
							 :deletable="disdeletable" max-count="9">
										
										<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
											<image src="../../static/mine/homepage/photo.png" style="width: 214upx;height: 214upx;margin:10upx;" />
										</view>
									</u-upload>
								</view>
							</view>
						</view>
					</view>
				</view>
			</u-form>
			<view class="btn" v-if="statusTitle != '审核中'" @click="submit">保存</view>
			<u-popup v-model="popupActive" mode="center">
				<view class="view-popup">
					<view style="margin-bottom: 20upx;">添加标签</view>
					<u-input  :disabled="disabled"  v-model="tagValue" placeholder="请输入标签" :border="true" />
					<view style="display: flex;margin-top: 20upx;">
						<u-button style="height: 60upx;" @click="popupActive = false">取消</u-button>
						<u-button style="height: 60upx;" @click="handleAddTag" type="primary">确认</u-button>
					</view>
				</view>
			</u-popup>
		</view>
		
		<u-calendar v-model="dqActive" mode="range" @change="handleSelectTime"></u-calendar>
		<u-select v-model="actionSheetShow" :list="actionSheetList" @confirm="confirm"></u-select>
		
		<TriTree ref="triTree" :range="fetchDict.all_adept_field" @confirm="function (e){return scsetChooseType(e,'specials')}"></TriTree>
		<TriTree ref="zytriTree" :range="fetchDict.financing_cooperation_project_category" @confirm="function (e){return scsetChooseType(e,'professional')}"></TriTree>
		 <TriTree ref="qyTree" :range="fetchDict.company_type" @confirm="function (e){return scsetChooseType(e,'userIdentify')}"></TriTree>
		<u-toast ref="uToast" />
		<!--引用组件-->
		<u-skeleton :loading="loading" :animation="true" bgColor="#FFF"></u-skeleton>
			<city-select v-model="cityActive" @city-change="cityChange"></city-select>
	</view>
</template>

<script>
	import citySelect from '@/components/u-city-select.vue'
	export default {
		components: {
			citySelect
		},
		data() {
			return {
				cityActive: false,
				userCode:'',
				loading: true, // 是否显示骨架屏组件
				showWorkingSeniority:false,
				diplomas:[],
				cardIds:[],
				labelPosition: 'left',
				professionalShow:false,
				professionalList:[],
				mSelectShow:false,
				disabled:false,
				statusTitle:'',
				proUrls:[],
				credentialsUrls:[],
				baseUrl:this.$mConfig.baseUrl,
				logoMask: this.$mAssetsPath.logoMask,
				avatar:this.$mAssetsPath.avatar,
				//选择城市
				showCity: false,
				defaultValue: [3],
				listCitys:[],
				identity:'个人身份',
				userIdentifyShow:false,
				userIdentifyList:[],
				showDate:false,
				show: false,
				mode: 'range',
				result: "请选择日期",
				startText: '开始',
				endText: '结束',
				rangeColor: '#2979ff',
				rangeBgColor: 'rgba(41,121,255,0.13)',
				activeBgColor: '#2979ff',
				action: this.$apis.uploadFile,
				errorType: ['toast'],
				tagValue: '',				
				specialtyKey:'',
				specialtyShow: false,
				rangKey:'pname',
				specialtyList:[],
				professionShow:false,
				credentialsShow:false,
				selfTagShow:false,
				sexList:[
					{
						name: '男',
						checked: false,
						disabled: false
					},
					{
						name: '女',
						checked: false,
						disabled: false
					},
					{
						name: '保密',
						checked: false,
						disabled: false
					},
				],
				selfTag: '',
				infoList: [{
					name: '',
					content: '',
					imgUrl: '',
				}],
				form: {
					industry:'',
					imgUrl: '../../static/homepage/tdmckk.png',
					cardName: '',
					sex: '',
					sexValue: '',
					school: '',
					major: '',
					workingSeniority: '',
					profession: '',
					proUrl: '',
					credentials: '',
					credentialsUrl: '',
					startScheduleTime: '',
					endScheduleTime: '',
					workUnit: '',
					workplace: '',
					telephone: '',
					mail: '',
					customize: null,
					texts: '',
					schedule: ''
				},
				rules: {
					industry: [{
						required: true,
						message: '请输入产业',
						trigger: 'blur'
					}],
					cardName: [
						{
							required: true,
							message: '请输入姓名',
							trigger: 'blur' ,
						},
						{
							min: 2,
							max: 5,
							message: '姓名必须2~4个汉字以内',
							trigger: ['change','blur'],
						},
						{
							// 此为同步验证，可以直接返回true或者false，如果是异步验证，稍微不同，见下方说明
							validator: (rule, value, callback) => {
								// 调用uView自带的js验证规则，详见：https://www.uviewui.com/js/test.html
								return this.$u.test.chinese(value);
							},
							message: '姓名必须为中文',
							// 触发器可以同时用blur和change，二者之间用英文逗号隔开
							trigger: ['change','blur'],
						},
					],
					// imgUrl: [{
					// 	required: true,
					// 	message: '请选择头像',
					// 	trigger: ['blur', 'change']
					// }, {
					// 	validator: function(rule, value, callback) {
					// 		if (value === '../../static/homepage/tdmckk.png') {
					// 			callback(new Error("请选择头像"));
					// 		} else {
					// 			callback();
					// 		}
					// 	},
					// 	trigger: 'blur'
					// }],
					sex: [
						{
							required: true,
							message: '请选择性别',
							trigger: 'change'
						}
					],
					school: [{
						required: true,
						message: '请输入毕业院校',
						trigger: ['blur', 'change']
					}],
					major: [{
						required: true,
						message: '请输入专业',
						trigger: ['blur', 'change']
					}],		
					telephone: [
						{
							required: true,
							message: '请输入手机号',
							trigger: ['change','blur'],
						},
						{
							validator: (rule, value, callback) => {
								return this.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							trigger: ['change','blur'],
						}
					],
					mail: [
						{
							required: true,
							message: '请输入邮箱',
							trigger: ['change','blur'],
						},
						{
							validator: (rule, value, callback) => {
								return this.$u.test.email(value);
							},
							message: '邮箱不正确',
							trigger: ['change','blur'],
						}
					]
				},
				required: true,
				popupActive: false,
				dqActive: false,
				schedule: {},
				tagList: [],
				actionSheetList: [{
						label: '不限',
						value: 0
					},
					{
						label: '女',
						value: 1
					},
					{
						label: '男',
						value: 2
					}
				],
				actionSheetShow: false,
				customize: '',
				customizeFlag:false,
				baseUrl: this.$mConfig.baseUrl,
				uploadImageIndex: null,
				fetchDict:[],
				cy:'',
				fileList: [],
				fileListZl: [],
				fileListZz: [],
				photos: [],
				zphotos: [],
				popupActive: false,
				showUploadList: true,
				showUploadListZz: true,
				customBtn: false,
				autoUpload: true,
				showProgress: false,
				deletable: true,
				disdeletable:false,
				customStyle: false,
				maxCount: 1,
				lists: [], // 组件内部的文件列表
				filePaths: '', // 文件路径
				filePathsZl: '', // 文件路径
				filePathsZz: '', // 文件路径
				fileNames: '', // 文件名称
				workingSenioritys:this.$mConstDataConfig.YearsService
			}
		},
		watch: {
			tagList(val) {
				this.form.selfTag = val.join(',')
			},
			avatar(v){
				console.log("v",v);
				this.avatar = v;
			}
		},
		onShow() {
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			//console.log('pages',pages)
			if (currPage.customizeFlag) {
				//console.log('aaaaa',currPage)
				this.form.customize = currPage.customize; //这就是传递的参数
				//console.log('bbbbb',this.form.customize)
			}
			this.getfetchUserReviewed();
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		created() {
			var that = this;
			// 监听从裁剪页发布的事件，获得裁剪结果
			uni.$on('uAvatarCropper', path => {
				
				// 可以在此上传到服务端
				uni.uploadFile({
					url: this.$apis.uploadFile,
					filePath: path,
					name: 'file',
					complete: (res) => {
						let img = JSON.parse(res.data);
						console.log(res);
						this.form.imgUrl = img.message;						
						this.avatar = that.baseUrl + img.message;
						this.$forceUpdate();
					}
				});
			})
		},
		onLoad(options) {	
			
			if(options.row){	
				this.findUserinfoList();
				this.form = JSON.parse(decodeURIComponent(options.row));
				console.log('row:',this.form);
			}
			this.cityList();//选择地区
		},
		onShow(){
			var keys = {'keys':['industry','financing_cooperation_project_category','all_adept_field','company_type']}
			this.dictionaryFetchDict(keys);
			
			if(this.$store.state.userInfo.identityType !== undefined){
				this.getIdentitys();
			}
			
			this.findUserInfoOne();
		},
		methods: {
			
			cityChange(e) {
				let address = e.province.label
				if(e.city){
					address = address + '-' + e.city.label;
				}
				if(e.area){
					address = address + '-' + e.area.label;
				}
				this.form.workplace = address
			},
			qySelect() {
				this.$refs.qyTree._show()
			},
			previewImage(index,files) { //预览图片
				let imgs = files;					
				let urls = [];
				for(var i in imgs){
					urls.push(this.baseUrl + imgs[i]);
				}
				console.log(urls);
				uni.previewImage({
					current:index,
					urls: urls
				});
			},
			onUploadedZl(lists) {
				var filePaths = [],
					fileNames = [];
				for (let i in lists) {
					console.log('data', lists[i].response);
					if (lists[i].response.code == 200) {
						filePaths.push(lists[i].response.message);
					}
				}
				this.form.diploma = filePaths.join(',');
			},
			onUploadedCard(lists) {
				var filePaths = [],
					fileNames = [];
				for (let i in lists) {
					console.log('data', lists[i].response);
					if (lists[i].response.code == 200) {
						filePaths.push(lists[i].response.message);
					}
				}
				this.form.cardId = filePaths.join(',');
			},
			mSelect() {
				this.$refs.triTree._show()
			},
			zySelect() {
				this.$refs.zytriTree._show()
			},
			showLB(){
				if(this.cy == ''){
					uni.showToast({
						title:"请先选择产业",
						icon:'none'
					})
					return;
				}
				this.specialtyShow = true;
				
			},
			async dictionaryFetchDict(keyWords) {
				let result = await this.$apis.fetchMultipleKey(keyWords);
				if(result.code == 200){
					this.loading = false;
				}
				this.fetchDict = result.data;
			},
			
			scsetChooseType(item, type) {
				console.log("column_array", item, type);
				var column_array = this.$mUtils.array_column(item, 'label');
				var modelValue = column_array.join(',');
				this.form[type] = modelValue;
				this.$forceUpdate()
			},
			setChooseType(item, type) {
				var column_array = this.$mUtils.array_column(item, 'label');
				var modelValue = column_array.join(',');
				this.form[type] = modelValue;
				this.cy = item[0].parents.length > 0?item[0].parents[0].id:item[0].id;
				console.log("cy",this.cy);
				var cyValue = item[0].parents.length > 0?item[0].parents[0].label:item[0].label;
				
				this.getfetchProfessionById(this.cy);
				
				this.form.profession = '';
				this.form.credentials = '';
				this.form.expertise = '';
				this.form.specialty = '';
				this.$forceUpdate()
			},
			async getfetchProfessionById(id){
				let result = await this.$apis.fetchProfessionById({id:id});
				this.specialtyList = result.data;
				this.specialtyKey = 0;
			},
			psetChooseType(item, type) {
				var column_array = this.$mUtils.array_column(item, 'label');
				var modelValue = column_array.join(',');
				this.form[type] = modelValue;
				this.$forceUpdate()
			},
			cySelect() {
				this.$refs.cyTree._show()
			},
			async getfetchUserReviewed(){
				if(uni.getStorageSync('token')){
					let result = await this.$apis.fetchUserReviewed();
					if(result.data != 1){
						this.statusTitle = result.message;
						this.disabled = result.message == '审核中'?true:false;
					}	
				}
			},
			onRemove(index, lists) {
				 console.log('onRemove', index, lists);
				 this.fileList.splice(index, 1)
				 console.log(this.fileList);
				 this.filePaths = this.fileList;
			},
			chooseAvatar() {
				// 此为uView的跳转方法，详见"文档-JS"部分，也可以用uni的uni.navigateTo
				this.$u.route({
					// 关于此路径，请见下方"注意事项"
					url: '/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
					// 内部已设置以下默认参数值，可不传这些参数
					params: {
						// 输出图片宽度，高等于宽，单位px
						destWidth: 300,
						// 裁剪框宽度，高等于宽，单位px
						rectWidth: 200,
						// 输出的图片类型，如果'png'类型发现裁剪的图片太大，改成"jpg"即可
						fileType: 'jpg',
					}
				})
			},
			// checkbox选择发生变化
			checkboxGroupChange(e) {
				this.form.sex = e;				
			},			
			confirmCity(e) {
				this.form.workplace = '';
				e.map((val, index) => {
					this.form.workplace += this.form.workplace == '' ? val.label : '-' + val.label;
				})
			},
			async cityList(){
			let result = await this.$apis.fetchArea({level:2});	
				this.listCitys = result.data;
			},			
			credentialsActive(){
				if(this.specialtyKey === ''){
					uni.showToast({
						title:"请先选择专业",
						icon:'none'
					})
				}else{
					this.addcredentialsActive = true;
				}
			},	
			async handleAddCredentials() {
				if (this.credentialsValue === '') {
					this.$refs.uToast.show({
						title: '职称不能为空',
						type: 'warning',
					})
				} else {					
					let saveData = this.specialtyList[this.specialtyKey];
					saveData.qualificationCert.push(this.credentialsValue);
					let result = await this.$apis.editProfession(saveData);								this.form.credentials = this.credentialsValue;
					this.credentialsValue = '';
					this.addcredentialsActive = false;
				}
			},
			
			professionActive(){
				if(this.cy === ''){
					uni.showToast({
						title:"请先选择专业",
						icon:'none'
					})
				}else{
					this.addprofessionActive = true;
				}
			},		
			async handleAddProfession() {				
				if (this.professionValue === '') {
					this.$refs.uToast.show({
						title: '职称不能为空',
						type: 'warning',
					})
				} else {					
					let saveData = this.specialtyList[this.specialtyKey];
					saveData.professionalDirectory.push(this.professionValue);
					let result = await this.$apis.editProfession(saveData);								this.form.profession = this.professionValue;
					this.professionValue = '';
					this.addprofessionActive = false;
				}
			},
			showProfession(){
				if(this.cy === ''){
					uni.showToast({
						title:"请先选择产业",
						icon:'none'
					})
					return;
				}
				this.professionShow = true;
				
			},			
			showCredentials(){
				if(this.cy === ''){
					uni.showToast({
						title:"请先选择产业",
						icon:'none'
					})
				}else{
					this.credentialsShow = true;
				}
			},
			mSelectShowClick(){
				if(this.cy === ''){
					uni.showToast({
						title:"请先选择产业",
						icon:'none'
					})
				}else{
					console.log("areaOfExpertise",this.specialtyList[this.specialtyKey].areaOfExpertise);
					this.mSelectShow = true;
				}
			},
			confirm(e,list,type){
				if(type == 'specialty'){					
					this.form[type] = list[e][this.rangKey];
					var specialtyKey = e[0];
					this.specialtyKey = specialtyKey;
					console.log("specialtyKey",specialtyKey);
				}else if(type == 'userIdentify'){	
					var itemKey = e[0];
					this.form[type] = list[itemKey]['name'];
				}else{
					var itemKey = e[0];
					this.form[type] = list[itemKey];
				}
					console.log("model:",this.form);
			},
			nxconfirm(e,list,type){
				var itemKey = e[0];
				this.form[type] = list[itemKey].value;				
			},
			async getIdentitys(){
				var userInfo = uni.getStorageSync('userInfo');
				if(userInfo.identityType !== undefined){
					let result = await this.$apis.identify({type:1});
					this.userIdentifyList = result.data;
				}
			},
			handleClickWeight(e) {
				//console.log("跳转：",this.form)
				var model = encodeURIComponent(JSON.stringify(this.form));
				let url = encodeURIComponent(JSON.stringify("user/myCompanyPage"));
				uni.navigateTo({
					url: '../user/personWeight?type='+url+'&row=' + model
				})
			},
			change(e) {
				this.form.schedule = e.startDate + " - " + e.endDate;				
			},
			async findUserInfoOne() {
				let that = this;
				let result = await this.$apis.fetchUserReviewed({id:this.$store.state.userInfo.id});
				if(result.data != 1){
					this.statusTitle = result.message;
					this.disabled = result.message == '审核中'?true:false;
				}
				let data = await this.$apis.findUserInfoOne();
				this.userCode = data.data.code;
				if (data.data.userInfo != null) {
					this.form = data.data.userInfo;
					if(this.form.proUrl != '' && this.form.proUrl != null){	
						this.proUrls = (this.form.proUrl.indexOf(',') === -1)?this.form.proUrl.split(','):[this.form.proUrl];
					}
					if(this.form.credentialsUrl != '' && this.form.credentialsUrl != null){	
						this.credentialsUrls = (this.form.credentialsUrl.indexOf(',') === -1)?this.form.credentialsUrl.split(','):[this.form.credentialsUrl];
					}
					if(data.data.products != undefined){
						
						this.infoList = data.data.products;
						//if(!data.data.userInfo.completeFlag) this.statusTitle = "审核中";
						for (let i = 0; i < this.infoList.length; i++) {
							if(this.infoList[i].imgUrl != null) this.infoList[i].arr=this.infoList[i].imgUrl.indexOf(',') !== -1?this.infoList[i].imgUrl.split(','):this.infoList[i].imgUrl;
							if(this.infoList[i].imgUrl.indexOf(',') != -1){
								for (var j = 0; j < this.infoList[i].arr.length; j++) {
									console.log(this.infoList[i].arr[j]);
									this.infoList[i].arr[j] = that.baseUrl+this.infoList[i].arr[j];
								}
							}else{
								this.infoList[i].arr = [that.baseUrl+this.infoList[i].arr];
							}
						}
					}
					if(this.form.imgUrl != null) this.avatar = this.baseUrl + this.form.imgUrl;
					if(this.form.diploma != null && this.form.diploma != ''){
						if(this.form.diploma.indexOf(',') !== -1){
							this.diplomas = this.form.diploma.split(',');
						}else{
							this.diplomas = [this.form.diploma];
						}
					}
					
					if(this.form.diploma != null && this.form.diploma != ''){
						if(this.form.diploma.indexOf(',') !== -1){
							this.diplomas = this.form.diploma.split(',');
							for (var j = 0; j < this.diplomas.length; j++) {
								this.diplomas[j] = {
									'url': that.baseUrl + this.diplomas[j]
								}
							}	
						}else{
							this.diplomas = [{'url': that.baseUrl + this.form.diploma}];
						}
					}
					
					if(this.form.cardId != null && this.form.cardId != ''){
						if(this.form.cardId.indexOf(',') !== -1){
							this.cardIds = this.form.cardId.split(',');
							for (var j = 0; j < this.cardIds.length; j++) {
								this.cardIds[j] = {
									'url': that.baseUrl + this.cardIds[j]
								}
							}	
						}else{
							this.cardIds = [{'url': that.baseUrl + this.form.cardId}];
						}
					}
					
					//console.log('this.infoList',this.infoList)
					if (this.form.sex!==null) {
						if (this.form.sex === 0) {
							this.form.sexValue = '不限'
						} else if (this.form.sex === 1) {
							this.form.sexValue = '女'
						} else if (this.form.sex === 2) {
							this.form.sexValue = '男'
						}
					}
					
					// if(this.form.proUrl){
					// 	this.form.proUrl=this.baseUrl+this.form.proUrl;
					// }
					// if(this.form.credentialsUrl){
					// 	this.form.credentialsUrl=this.baseUrl+this.form.credentialsUrl;
					// }
					if(this.form.selfTag != undefined){
						if(this.form.selfTag.indexOf(',') !== -1){
							this.form.selfTag.split(',').forEach(function(item){
								that.tagList.push(item)
							})
						}
					}
					//console.log('this.tagList',this.tagList)
					console.log('findUserInfoOne', this.form)
				}
			},
			async findUserinfoList() {
				let that = this;
				let data = await this.$apis.findUserInfoOne();
				if (data.code === 200) {
					this.infoList = data.data.products;
					for (let i = 0; i < this.infoList.length; i++) {
						this.infoList[i].arr=this.infoList[i].imgUrl.split(',');
						for (var j = 0; j < this.infoList[i].arr.length; j++) {
							this.infoList[i].arr[j] = that.baseUrl+this.infoList[i].arr[j]
						}
					}
				}
			},
			getImageTypeIndex: function(index) {
				this.uploadImageIndex = index
			},
			handleClickAddInfo() {
				let obj = {
					name: '',
					content: '',
					imgUrl: '',
				};
				this.infoList.push(obj);
			},
			avaUploadSuccess(data) {
				console.log(data.message);
				this.form.imgUrl = data.message;
				//console.log(this.form.imgUrl)
			},
			avaUploadSuccess2(data) {
				this.proUrls.push(data.message);
				this.form.proUrl = this.proUrls.join(',');
				//console.log(this.form.proUrl)
			},
			avaUploadSuccess3(data) {
				this.credentialsUrls.push(data.message);	
				this.form.credentialsUrl = this.credentialsUrls.join(',');			
				//console.log(this.form.credentialsUrl)
			},
			avaUploadSuccess4(data) {
				//console.log('this.uploadImageIndex', this.uploadImageIndex)
				//console.log('this.infoList', this.infoList)
				if (this.infoList[this.uploadImageIndex].imgUrl === '') {
					this.infoList[this.uploadImageIndex].imgUrl = data.message;
				} else {
					this.infoList[this.uploadImageIndex].imgUrl =this.infoList[this.uploadImageIndex].imgUrl+ ',' + data.message;
				}
			},
			handleClearProUrl(e) {
				this.proUrls.splice(e,1);
				this.form.proUrl = JSON.stringify(this.proUrls) != '{}' ? this.proUrls.join(','):'';
			},
			handleClearProUrl2(e) {
				this.credentialsUrls.splice(e,1);
				this.form.credentialsUrl = JSON.stringify(this.credentialsUrls) != '{}' ? this.credentialsUrls.join(','):'';
			},
			submit() {
				var that = this;
				//console.log('this.infoList', this.infoList)
				this.$refs.uForm.validate(valid => {
					//console.log('valid', valid)
					if (valid) {
						//console.log('111', this.infoList)
						let flag = true;
						this.infoList.forEach(function(item) {
							if (item.name === '') {
								that.$refs.uToast.show({
									title: '产品信息介绍分类名称不能为空',
									type: 'default',
								})
								flag = false;
							} else if (item.content == '') {
								that.$refs.uToast.show({
									title: '产品信息介绍产品说明不能为空',
									type: 'default',
								})
								flag = false;
							} else if (item.imgUrl == '') {
								that.$refs.uToast.show({
									title: '产品信息介绍图片不能为空',
									type: 'default',
								})
								flag = false;
							}
							// else {
							// 	//console.log('success submit', that.form)
							// 	that.saveProducts(JSON.stringify(that.infoList));
							// }
						})
						if (flag) {
							// //console.log('success submit', that.form)
							that.saveUserInfo();
						}
						//console.log('验证通过', flag);
					} else {
						//console.log('验证失败');
					}
				});
			},
			async saveUserInfo() {
				let obj = this.form;
				//obj.imgUrl = obj.imgUrl.slice(this.baseUrl.length)
				//obj.credentialsUrl = obj.credentialsUrl.slice(this.baseUrl.length)
				//obj.proUrl = obj.proUrl.slice(this.baseUrl.length)
				let arr = this.infoList;
				arr.forEach(function(item){
					delete item.arr
				})
				this.saveProducts(JSON.stringify(arr));
				//console.log('this.form1111', obj)
				let data = await this.$apis.saveUserInfo(obj);
				if (data.code === 200) {
					this.$refs.uToast.show({
						title: '保存成功',
						type: 'success',
						back: 'true'
					})
					this.findUserInfoOne();
				}
			},
			async saveProducts(e) {
				let data = await this.$apis.saveProducts(e);
			},
			handleClickCustom(e) {
				uni.navigateTo({
					url: '../user/custom?row=' + encodeURIComponent(e)
				})
			},
			handleAddTag() {
				if (this.tagValue === '') {
					this.$refs.uToast.show({
						title: '标签不能为空',
						type: 'warning',
					})
				} else {
					this.tagList.push(this.tagValue);
					this.tagValue = '';
					this.popupActive = false;
				}
			},
			tagClick(e) {
				//console.log(e)
				this.tagList.splice(e, 1);
			},
			handleSelectTime(e) {
				//console.log(e)
				this.form.schedule = e.startDate + '~' + e.endDate;
				this.form.startScheduleTime = e.startDate;
				this.form.endScheduleTime = e.endDate;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.slot-btn {
		display: flex;
		justify-content: center;
	}

	.container {
		.btn {
			width: 662upx;
			height: 80upx;
			background: #AB61FF;
			border-radius: 40upx;
			border: none;
			line-height: 80upx;
			color: #fff;
			font-size: 30upx;
			text-align: center;
			margin: 140upx 43upx 78upx 43upx;
		}

		.view-popup {
			padding: 30upx;
		}

		.content {
			padding: 40upx 20upx;

			.cpInfoList {
				width: 100%;
				margin-top: 40upx;

				.infoItem {
					background: #F5F5F9;
					padding: 30upx 24upx;
					margin-top: 20upx;
					margin-left: 20upx;
					margin-right: 20upx;
					box-sizing: border-box;
					margin-bottom: 50upx;

					.item-cell {
						display: flex;
						justify-content: space-between;
						margin-bottom: 30upx;

						.infoItem-title {
							font-size: 30upx;
						}

						input {
							width: 430upx;
						}
					}
				}
			}

			.u-form-item {
				padding: 10upx 20upx;

				.scroll-view_H {
					width: 380upx;
					white-space: nowrap;
				}
			}

			.line-break {
				/deep/ .u-form-item__body {
					display: block;
				}
			}

			.header {
				width: 100%;
				height: 50upx;
				display: flex;
				align-items: center;
				margin-top: 50upx;

				.header-title {
					color: #0D1D36;
					font-size: 38upx;
					margin-left: 12upx;
				}

				.header-icon {
					width: 30upx;
					height: 34upx;
					margin-left: 30upx;
				}
			}

			.avatar {
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;

				.name {
					color: #4B9CFF;
					font-size: 30upx;
				}

				.topic {
					width: 115upx;
					height: 132upx;
					margin-left: -20upx;
				}
			}
		}

		.line {
			width: 100%;
			height: 20upx;
			background-color: #F5F5F9;
		}
	}
	
	.sctp {
		display: flex;
		flex-direction: column;
	
		.hz {
			color: #0d1d36;
			font-size: 30rpx;
		}
	
		.sm {
			color: #9da2b0;
			font-size: 26rpx;
			line-height: 44rpx;
			margin-top: 38rpx;
		}
	}
	
	.f-logo {
		width: 115rpx;
		height: 132rpx;
		overflow: hidden;
		background-repeat: no-repeat;
		background-position:center 0;
		background-size: 115% auto;
		image {
			width: 115rpx;
			height: 132rpx;
		}
	}
</style>
